package com.itheima.service.mongo.impl;

import com.itheima.domain.mongo.Visitor;
import com.itheima.service.mongo.VisitorService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;


import java.util.List;

@Service
public class VisitorServiceImpl implements VisitorService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<Visitor> findVisitorList(Long userId, String time) {
        Query query = new Query(Criteria.where("userId").is(userId).and("date").gt(Long.parseLong(time))).with(Sort.by(Sort.Order.desc("date"))).skip(0).limit(4);
        List<Visitor> visitorList = mongoTemplate.find(query, Visitor.class);
        return visitorList;
    }
}
